#include "ip.h"

void encode_ip_hdr_pkt(uint8_t * msg, uint16_t total_len, uint8_t next_proto_id, uint32_t s_ip, uint32_t d_ip){
    struct rte_ipv4_hdr * iphdr = (struct rte_ipv4_hdr*)(msg + sizeof(struct rte_ether_hdr));
    iphdr->version_ihl = 0x45;
    iphdr->type_of_service = 0;   // 服务类型；如流媒体等
    iphdr->total_length = htons(total_len);  // 整个ip包长度
    iphdr->packet_id = 0;   // 标识：当发送连续包时有用
    iphdr->fragment_offset = 0;   // 偏移位
    // ttl 无符号8位；回环 128 （高位置1）；其他第二位置1
    iphdr->time_to_live = 64; // ttl = 64
    iphdr->next_proto_id = next_proto_id;
    iphdr->src_addr = s_ip;
    iphdr->dst_addr = d_ip;
    iphdr->hdr_checksum = 0;
    iphdr->hdr_checksum = rte_ipv4_cksum(iphdr);
}